<?php
namespace Home\Model;
use Think\Model;
class UserCaptdetailModel extends Model
{
    
    
    protected $_auto = array (
        array('createdate','date',1,'function',array('Y-m-d H:i:s')), // 对create_time字段在插入的时候写入当前时间
    );
    protected $_validate = array(
        array('uid','require','用户ID不能为空！'), //默认情况下用正则进行验证
        array('tran_income',array(1,2,3,4,5),'交易类型不正确！',1,'in'), // 1=现金红包，2=支付充值，3=银行卡提现，4=域名交易费，5=手续费
        array('tran_type',array(1,2),'收支类型不正确！',1,'in'), // 1=收入 2=支出
    );
     
     /**
      * 插入用户资金交易明细
      * @param unknown 
      * @return number|unknown
      */
	public function inser($arry)
	{
        foreach ($arry as $key => $value){
	        $data[$key] = $value;
	    };
	    $res["status"]=0;
	    if (!$this->create($data)){
	        $result["msg"]=$this->getError();
	    }else{
	        $result = $this->add(); // 写入数据到数据库 
            if($result){
                $res["status"]=1;
                $res["msg"]="成功";
            };
	    };
	    return $res;
	}
	/**
	 * 条件查询用户资金交易明细
	 * @param unknown $arry
	 */
	public function getList($uid,$queryTime)
	{
	    $con['uid'] =$uid;
	    if($queryTime != 9){
                $con["createdate"] = array('between', array(date('Y-m-d 00:00:00',time()-60*60*24*30*$queryTime),date('Y-m-d 23:59:59', time())));
	    };
        return $this->where($con)->select();
	}
	
	public function getCount($uid,$queryTime)
	{
	    $con['uid'] =$uid;
	    if($queryTime != 9){
            $con["createdate"] = array('between', array(date('Y-m-d 00:00:00',time()-60*60*24*30*$queryTime),date('Y-m-d 23:59:59', time())));
	    };
	    return $this->where($con)->count();
	}
}
?>